<template>
  <div class="zhishifenlei">
    <div class="top">
      <div class="w1200 flex" style="display: flex; justify-content: space-between; align-items: center; height: 80px;">
        <div class="logo"><img :src="srclogo" @click="gos" style="cursor: pointer;  width: 247px; height: 49px;"></div>
        <!--        <div class="name">添加客服知识</div>-->
        <div class="nava">
          <router-link to="/shangpinlist">商品问题库</router-link>
          <router-link to="/kefulist">客服知识库</router-link>
        </div>
      </div>
    </div>
    <div class="center" ref="center">
      <div class="w1200">
        <div class="centerall">

          <div style="padding:20px 0;">
             <el-button type="danger" style="margin-bottom: 20px;" round @click="xinzengfenlei">新增分类</el-button>
            <el-table :data="list" border style="width: 100%">

              <el-table-column prop="name" align="center" label="分类名称">
              </el-table-column>
              <el-table-column prop="created_at" align="center" label="时间">
              </el-table-column>
              <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                  <!-- <el-button size="mini" type="text" @click="xiugai(scope.row.id)">修改</el-button> -->
                  <el-button size="mini" type="text" @click="shanchu(scope.row.id)">删除</el-button>
                </template>
              </el-table-column>

            </el-table>
          </div>
        </div>
      </div>
    </div>
    <el-dialog title="新增知识分类" center :close-on-click-modal="false" :visible.sync="log" @opened="logshow" width="440px">

        <div>
          <el-input v-model="name" style="width: 400px;" placeholder="知识分类名称"></el-input>
        </div>

      <span slot="footer" class="dialog-footer">
        <el-button type="info" round @click="log = false">取 消</el-button>
        <el-button type="danger" round @click="fabutongzhi" :disabled="ing">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import axios from "axios";
  export default {
    name: 'zhishifenlei',
    data() {
      return {
        srclogo:"./static/img/zhishilogo2.png",
        log:false,
        name:"",
        total:0,
        list:"",
        ing:false
      }
    },
    created() {
      this.getlist()
    },
    mounted() {
      this.$refs.center.style.minHeight = document.documentElement.clientHeight - 80 + 'px'
    },
    methods: {
      xinzengfenlei:function(){
        this.log = true
        this.name = ""
      },
      // xiugai:function(item){
      //   this.all = JSON.parse(JSON.stringify(item))
      // },
      gos: function() {
        window.location.href = window.location.origin + window.location.pathname + '#/' + 'index'
      },
      fabutongzhi:function(){
        this.ing = true
        axios.post('/api/plan-market/question/type/create', {
            name: this.name
          })
          .then(response => {
            if (response.data.msg.code == 0) {
              this.$message.success('新增成功');
              this.getlist()
              this.log = false
              setTimeout(()=>{
                this.ing  =  false
              },500)
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
      //删除
      shanchu: function(id) {
         this.$confirm('此操作将永久删除, 是否继续?', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                }).then(() => {
                  axios.post('/api/plan-market/question/type/delete', {
                      id: id
                    })
                    .then(response => {
                      if (response.data.msg.code == 0) {
                        this.$message.success('删除');
                        this.getlist()
                      } else {
                        this.$message.error(response.data.msg.info);
                      }
                    })
                })
      },
      //翻页
      fanye: function(page) {
        this.page = page
        this.getlist()
      },
      //获取
      getlist: function() {
        var that = this
        axios.get('/api/plan-market/question/type/list')
          .then(response => {
            if (response.data.msg.code == 0) {
              this.list = response.data.data
              this.total = response.data.data.total
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
    }
  }
</script>

<style lang="scss" scoped>
  .zhishifenlei {
    margin: 0;
    padding: 0;
    background: #ffffff;
    font-family: "Microsoft JhengHei";

    /deep/ .el-button--danger {
        color: #FFF;
        background-color: #2974FF;
        border-color: #2974FF;
    }

    .w1200 {
      width: 1200px;
      margin: 0 auto;
    }

    .top {
      height: 80px;
      background: #42628D;
      display: flex;
      color: #ffffff;
      font-size: 25px;
      font-weight: bold;
    }

    .nava {
      a {
        color: #ffffff;
        font-size: 16px;
        margin-right: 20px;
        padding: 10px 0;
        position: relative;
        top: 10px;
      }
    }

    .router-link-active {
      border-bottom: 4px #ffffff solid;
      font-weight: bold;
    }

    .name {
      display: flex;
      align-items: center;
      height: 80px;
    }

    .centerall {}

  }
</style>
